<template>
	<div @click="cancelPop" style="height: 100%;">
	<div class="menu-box">
		<div class="setting-btn-box" @click.stop="showMenu">
			<div></div>
		</div>
		<div v-if="isShowMenu" class="menu">
			<ul>
			<li v-for="mod in modules" :key="mod.path" @click="onMod(mod.path)">{{ mod.name }}</li>
			</ul>
		</div>
	</div>
	<div class="main-box">
		<div class="page-name">{{ getPageName() }}</div>
		<slot></slot>
	</div>
	</div>
</template>
<script>
let modules = null;
let modMapping = {};

export default {
	props: {
	name: {
		type: String,
		default: ""
	}
	},
	data () {
	return {
		isShowMenu: false,
		modules: [],
	}
	},
	created () {
	this.getDatas();
	},
	methods: {
		async getDatas () {
			if (modules === null) {
				try {
					modules = await $utils.readFile(`./res/modules.json`);

					for (const mod of modules) {
					const path = mod.path ? mod.path : "homepage";
					modMapping[path] = mod.name;
					}

					this.modules = modules;
				} finally {
				}
			} else {
				this.modules = modules;
			}

			if (this.$route.name === "home") {
				document.title = `首页 - ${process.env.VUE_APP_TITLE}`;
			} else {
				document.title = `${modMapping[this.$route.params.module]} -${process.env.VUE_APP_TITLE}`;
			}
		},
		showMenu () {
			this.isShowMenu = true;
		},
		onMod (path) {
			if ((path === this.name) || (path === "" && this.name === "homepage")) return;
			this.$router.push({ path: `/${path}` });
			this.isShowMenu = false;
		},
		cancelPop () {
			this.isShowMenu = false;
		},
		getPageName () {
			if (this.name === "homepage") {
				return process.env.VUE_APP_TITLE;
			}
		}
	}
}
</script>
<style lang="scss" scoped>

body {
	height: 100%;
	background: #FFFF00;
}

.menu-box, .main-box {
	display: inline-block;
	vertical-align: top;
}

.menu-box {
	width: 80px;
	position: relative;

	.menu {
	position: absolute;
	left: 30px;
	top: 15px;
	width: 200px;
	background: #F7F7F7;
	padding:10px;
	border-radius: 10px;

	ul, li {
		margin: 0px;
		padding: 0px;
		list-style: none;
	}

	li {
		padding:5px 10px;
		border-radius: 5px;
	}

	li:hover {
		background: #CCCCCC;
		cursor: pointer;
	}
	}

	.setting-btn-box {
	width: 36px;
	height: 18px;
	border-top: 6px solid #696479;
	border-bottom: 6px solid #696479;
	cursor: pointer;
	>div {
		border:0px;
		height: 6px;
		margin-top: 6px;
		background: #696479;
	}
	.setting-btn-box:hover {
		background: #000000;
	}
	}
}

.main-box {
	width: calc(100% - 80px);
	.page-name {
	font-size: 30px;
	font-weight: bold;
	}
}


</style>